import Taro from '@tarojs/taro-rn';
import * as tslib_1 from "tslib";
import React from 'react';
import { Component } from "@tarojs/taro-rn";
import { View, Switch, Input, Form, Button } from "@tarojs/components-rn";
import { inject, observer } from "@tarojs/mobx-rn";
import { getRuntime, isPhone } from "../../utils/common";
import PickerArea from "../../components/PickerArea";
import address_addStyleSheet from "./address_add_styles";
var _styleSheet = address_addStyleSheet;
let Personnel = class Personnel extends Component {
  constructor(props) {
    super(props);
    this.state = {
      allProvince: [],
      allCity: [],
      allDistract: [],
      provinceIndex: 0,
      cityIndex: 0,
      distractIndex: 0,
      area: null,
      addressInfo: null // 详细地址
    };
  }
  componentWillMount() {
    Taro.setNavigationBarTitle({ title: '添加收货地址' });
  }
  pickerArea(res) {
    this.setState({
      area: res.province.label + res.city.label + res.distract.label
    });
  }
  submit(e) {
    let { userStore } = this.props.stores;
    let { area } = this.state;
    let { receiver, receiverPhone, addressInfo } = e.detail.value;
    if (!receiver) {
      getRuntime().showToast('收货人姓名不能为空~');
      return false;
    }
    if (!receiverPhone) {
      getRuntime().showToast('收货人手机号码不能为空~');
      return false;
    }
    if (!isPhone(receiverPhone)) {
      getRuntime().showToast('收货人手机号码格式不正确~');
      return false;
    }
    if (!area) {
      getRuntime().showToast('请选择省市区信息~');
      return false;
    }
    if (!addressInfo) {
      getRuntime().showToast('请填写详细地址信息~');
      return false;
    }
    userStore.saveUserAddress({
      form: {
        receiver,
        receiverPhone,
        receiverAddress: area + '@' + addressInfo,
        postalCode: ''
      },
      callback: () => {
        getRuntime().showToast('保存地址成功~');
        setTimeout(() => {
          getRuntime().navigateBack();
        }, 2000);
      }
    });
  }
  render() {
    return <View style={_styleSheet["address-edit"]}>

      <Form onSubmit={this.submit.bind(this)}>
        <View style={_styleSheet["from-wrap"]}>
          <View style={_styleSheet["item-group"]}>
            <View style={_styleSheet["input-group"]}>
              <View style={_styleSheet["input-name"]}>收货人姓名</View>
              <Input name="receiver" placeholder="请填写收货人姓名" placeholderStyle={{ 'font-size': '26px' }} style={_styleSheet["from-input"]} />
            </View>

            <View style={_styleSheet["input-group"]}>
              <View style={_styleSheet["input-name"]}>手机号码</View>
              <Input name={'receiverPhone'} type={"number"} maxLength={11} placeholderClass="placeholder_class" placeholder="请填写手机号码" style={_styleSheet["from-input"]} />
            </View>

            <View style={_styleSheet["input-group"]}>
              <View style={_styleSheet["input-name"]}>省/市/区</View>
              <PickerArea onPicketArea={this.pickerArea.bind(this)} />
            </View>

            <View style={_styleSheet["input-group"]}>
              <View style={_styleSheet["input-name"]}>详细地址</View>
              <Input name="addressInfo" placeholderClass="placeholder_class" placeholder={'请填写详细地址'} style={_styleSheet["from-input"]} />
            </View>

          </View>

          <View style={_styleSheet["item-group"]}>
            <View style={[_styleSheet["input-group"], _styleSheet["input-switch"]]}>
              <View style={_styleSheet["input-name"]}>设为默认地址</View>
              <Switch color="#00a0e9" />
            </View>
          </View>
        </View>
        <Button formType="submit" style={_styleSheet["btn-line-submit"]}>保存</Button>
      </Form>


      </View>;
  }
};
Personnel = tslib_1.__decorate([inject("stores"), observer], Personnel);
export default Personnel;